package com.cuitrip.util;


import com.cuitrip.config.Config;
import com.cuitrip.mode.Language;
import com.cuitrip.mode.Rule;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

/**
 * Created by MiJack on 2015/11/21.
 */
public class FileUtil {
    public static String buildFileName(Config config, Rule rule, Language language) {
        return config.getOutputConfig().getOutputDir()
                + rule.getDir() + rule.getFileSample().replace("{short-name}", language.getShortName()).replace("{prefix}", language.getPrefix());
    }
    public static void checkFile(String file){
        File f = new File(file);
        String path = f.getParent();
        File pathF = new File(path);
        pathF.mkdirs();
    }
    public static void appendLine(String fileName, String content) throws IOException {
        Writer writer = new FileWriter(fileName, true);
        BufferedWriter bufferedWriter = new BufferedWriter(writer);
        bufferedWriter.write(content);
        bufferedWriter.newLine();
        bufferedWriter.close();
        writer.close();
    }


}
